package com.tongguan.paypos.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tongguan.paypos.R;
import com.tongguan.paypos.base.BaseFragment;
import com.tongguan.paypos.common.AppConstants;
import com.tongguan.paypos.entity.BillsInfo;
import com.tongguan.paypos.utils.Arith;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Joylive on 2016/12/18 .
 */

public class TransBillsOnlineDetailFragment extends BaseFragment {

    public static final String ORDER_DATA = "orderData";

    @BindView(R.id.tv_merchant_name)
    TextView mTvMerchantName;
    @BindView(R.id.tv_merchant_id)
    TextView mTvMerchantId;
    @BindView(R.id.tv_terminal_no)
    TextView mTvTerminalNo;
    @BindView(R.id.tv_order_id)
    TextView mTvOrderId;
    @BindView(R.id.tv_trade_up_order)
    TextView mTvTradeUpOrder;
    @BindView(R.id.ll_up_order)
    LinearLayout mLlUpOrder;
    @BindView(R.id.tv_pay_type)
    TextView mTvPayType;
    @BindView(R.id.tv_trans_type)
    TextView mTvTransType;
    @BindView(R.id.tv_order_state)
    TextView mTvOrderState;
    @BindView(R.id.tv_trans_time)
    TextView mTvTransTime;
    @BindView(R.id.ll_order_money)
    LinearLayout mLlOrderMoney;
    @BindView(R.id.ll_coupon_money)
    LinearLayout mLlCouponMoney;
    @BindView(R.id.tv_trans_amount)
    TextView mTvTransAmount;
    @BindView(R.id.tv_trans_money)
    TextView mTvMoney;
    @BindView(R.id.tv_trans_coupon_money)
    TextView mTvCouponMoney;

    private BillsInfo mTransInfo;
    private double money;//实付金额
    private double coupon_money;//优惠金额
    private double amount;//总金额

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_bills_online_detail, container, false);
        ButterKnife.bind(this, rootView);
        Bundle extras = getArguments();
        if (extras != null) {
            mTransInfo = extras.getParcelable(ORDER_DATA);
        }
        initView();
        return rootView;
    }

    private void initView() {
        mTvMerchantName.setText(mTransInfo.getMerchantName());
        mTvMerchantId.setText(mTransInfo.getMerchantId());
        mTvTerminalNo.setText(mTransInfo.getPosId());
        mTvOrderId.setText(mTransInfo.getOrderId());
        //上游订单号 （会员卡和现金没有）
        if ("XJ".equals(mTransInfo.getChannelId()) || "HYC".equals(mTransInfo.getChannelId())) {
            mLlUpOrder.setVisibility(View.GONE);
        } else {
            mTvTradeUpOrder.setText(mTransInfo.getUpOrderId());
        }
        String payTypeText = AppConstants.getPayTypeText(mTransInfo.getChannelId());
        mTvPayType.setText(payTypeText);
        String state = mTransInfo.getState();
        mTvTransType.setText(AppConstants.transType.get(state));
        mTvOrderState.setText(AppConstants.orderState.get(state));
        mTvTransTime.setText(mTransInfo.getPayTime());
        money = mTransInfo.getPayMoney();
        coupon_money = mTransInfo.getCouponMoney();//没有优惠金额
        if (coupon_money > 0) {
            mLlOrderMoney.setVisibility(View.VISIBLE);
            mLlCouponMoney.setVisibility(View.VISIBLE);
            mTvMoney.setText(String.valueOf(money));
            String temp = "-" + coupon_money;
            mTvCouponMoney.setText(temp);
            amount = Arith.sub(money, coupon_money);
            mTvTransAmount.setText(String.valueOf(amount));
        } else {
            amount = money;
            mTvTransAmount.setText(String.valueOf(amount));
        }
    }
}
